package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;


@Cmd(code = Protocol.C_UNION_MODIFY_FROM_ADMIN, desc = "后台修改商会信息")
public class CrossUnionModifyFromAdminCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionProto.CrossUnionModifyFromAdminMsg msg = CrossUnionProto.CrossUnionModifyFromAdminMsg.parseFrom(packet.getBytes());

        if(!StringUtils.isNullOrEmpty(msg.getUnionUid())){
            CrossUnionInfo unionInfo = CrossUnionMgr.getUnionInfo(msg.getUnionUid());
            if(unionInfo != null){
                if(msg.hasUnionName()){
                    unionInfo.setUnionName(msg.getUnionName());
                }
                if(msg.hasInnerNotice()){
                    unionInfo.setInnerNotice(msg.getInnerNotice());
                }
                if(msg.hasOutNotice()){
                    unionInfo.setOutNotice(msg.getOutNotice());
                }
                if(msg.hasQqCode()){
                    unionInfo.setQqCode(msg.getQqCode());
                }
                if(msg.hasWtCode()){
                    unionInfo.setWechatCode(msg.getWtCode());
                }
                if(msg.hasJoinLimit()){
                    //unionInfo.setim
                }
                if(msg.hasLevel()){

                }
                CrossUnionMgr.sendUnionChangeBroadcast(eUnionSyncType.Normal.getValue(), unionInfo, null, null, 0);
            }
        }

    }

    @Override
    public void sendData() {

    }
}
